package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {

    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    /**
     * 新增护理等级
     *
     * @param nursingLevelDto
     */
    @Override
    public void insert(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = new NursingLevel();
        BeanUtil.copyProperties(nursingLevelDto, nursingLevel);
        // 调用Mapper
        nursingLevelMapper.insert(nursingLevel);
    }

    /**
     * 分页条件查询
     *
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageResponse<NursingLevelVo> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        // 调用分页插件PageHelper
        PageHelper.startPage(pageNum, pageSize);
        // 调用Mapper
        Page<NursingLevelVo> page = nursingLevelMapper.getByPage(name, status);
        // PageResponse.of创建一个PageResponse对象实例，接收Page对象（分页信息）和Class对象（类的类型）
        return PageResponse.of(page, NursingLevelVo.class);
    }

    /**
     * 根据ID查询
     *
     * @param id
     * @return
     */
    @Override
    public NursingLevelVo getById(Integer id) {
        return nursingLevelMapper.getById(id);
    }

    /**
     * 更新护理等级
     *
     * @param nursingLevelDto
     */
    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        // 创建一个新的NursingLevel实例
        NursingLevel nursingLevel = new NursingLevel();

        // 使用BeanUtil工具类将nursingLevelDto的属性值复制到nursingLevel对象中
        BeanUtil.copyProperties(nursingLevelDto, nursingLevel);

        // 调用Mapper
        nursingLevelMapper.update(nursingLevel);
    }

    /**
     * 根据ID删除等级
     *
     * @param id
     */
    @Override
    public void delete(Integer id) {
        // 调用Mapper
        nursingLevelMapper.delete(id);
    }

    /**
     * 查询所有等级
     *
     * @return
     */
    @Override
    public List<NursingLevelVo> getAll() {
        // 调用Mapper
       return nursingLevelMapper.getAll();
    }

    /**
     * 启用禁用状态
     *
     * @param id
     * @param status
     */
    @Override
    public void updateStatus(Integer id, Integer status) {
        // 调用Mapper
        nursingLevelMapper.updateStatus(id, status);
    }
}
